package org.wlgzs.shop.controller.page;

import com.sun.tools.internal.xjc.Driver;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.wlgzs.shop.bean.*;
import org.wlgzs.shop.dao.GoodsDataMapper;
import org.wlgzs.shop.service.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class oneController {
    @Autowired
    IGoodsDateService goodsDateService;

    @Autowired
    IStoreService storeService;

    @Autowired
    GoodsDataMapper goodsDataMapper;

    @Autowired
    IManagerKind managerKind;

    @Autowired
    IOrderTransportDateService iOrderTransportDateService;

    @Autowired
    ICarDataService iCarDataService;

    @Autowired
    IShowStoreService showStoreService;

    @RequestMapping("/")
    @ResponseBody
    @ApiOperation(value ="主页跳转接口",httpMethod = "POST", response = ModelAndView.class)
    public ModelAndView to(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("/index");
        modelAndView.addObject("kindOne",managerKind.oneKind());
        modelAndView.addObject("hotGoods",goodsDateService.selectHotGoods());
        modelAndView.addObject("phoneGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("48"),4));
        modelAndView.addObject("milkGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("78"),4));
        modelAndView.addObject("drinkGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("86"),4));
        modelAndView.addObject("foodGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("81"),4));
        modelAndView.addObject("bookGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("111"),4));
        modelAndView.addObject("clothDate",goodsDateService.selectGoodsShow(goodsDateService.selectDate("186"),4));
        modelAndView.addObject("topDate",storeService.storeDate(storeService.allStore(),3));
        modelAndView.addObject("centerDate",storeService.storeDate(storeService.allStore(),10));
        return modelAndView;
    }

    @ApiOperation(value = "中转页面",httpMethod = "GET")
    @RequestMapping("/catch")
    public String jumpSpecial(String twoKindId){
        StringBuffer set=new StringBuffer("redirect:http://localhost:8080/common?");
        set.append("kindTwoId="+twoKindId+"&");
        set.append("oneKindId="+managerKind.selectTwoKind(twoKindId));
        return set.toString();
    }

    @ApiOperation(value = "中转页面",httpMethod = "GET")
    @RequestMapping("/catch2")
    public String jumpSpecial2(String kindStoreId){
        StringBuffer set=new StringBuffer("redirect:http://localhost:8080/common?");
        set.append("kindStoreId="+kindStoreId+"&");
        set.append("oneKindId="+managerKind.selectStr(kindStoreId));
        return set.toString();
    }


    @RequestMapping("/jump")
    public String jump(){
        return "test";
    }
    @ApiOperation(value = "跳转" ,httpMethod = "GET")
    @RequestMapping("brandSpike")
    public ModelAndView brandSpikeJump(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("spike/brandSpike");
        modelAndView.addObject("drinkGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("80"),3));
        modelAndView.addObject("foodGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("81"),3));
        modelAndView.addObject("bookGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("111"),2));
        modelAndView.addObject("clothDate",goodsDateService.selectGoodsShow(goodsDateService.selectDate("186"),2));
        modelAndView.addObject("milkGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("78"),2));
        return modelAndView;
    }

    @RequestMapping("pinSpike")
    public String pinSpikeJump(){
        return "spike/pinSpike";
    }

    @RequestMapping("vaultSpike")
    public ModelAndView vaultSpikeJump(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("spike/vaultSpike");
        modelAndView.addObject("drinkGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("80"),3));
        modelAndView.addObject("foodGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("81"),3));
        modelAndView.addObject("bookGoods",goodsDateService.selectGoodsShow(goodsDateService.selectDate("111"),3));
        modelAndView.addObject("clothDate",goodsDateService.selectGoodsShow(goodsDateService.selectDate("186"),3));
        return modelAndView;
    }

    @RequestMapping("/shoppingCart")
    public String shoppingCart(){ return "buy/shoppingCart"; }

    @RequestMapping("/shoppingSettlement")
    public String shoppingSettlement(){ return "buy/shoppingSettlement"; }


    @RequestMapping("/advise")
    public String JumpAdvise(){
        return "advice/advise";
    }


    @RequestMapping("/myVault")
    public String jumpMyVault(){
        return "my/MyVault";
    }

    @RequestMapping("/cashier")
    public String jumpcashier(){ return "goods/cashier"; }

    @RequestMapping("/myOrder")
    public String shoppingmyOrder(){
        return "my/myOrder"; }

    @RequestMapping("/clothingBags")
    public String clothingBags(){ return "shop/clothingBags";
        }

    @RequestMapping("/jumpShop")
    public String huaweiShop (int storeId,Model model)
    {
        model.addAttribute("allGoods",goodsDateService.selectGoodsShow(goodsDateService.selectGoodsByStore(storeId),5));
        model.addAttribute("goods",showStoreService.getStoreShowDate(storeId));
        return "shop/huaweiShop";
        }

    @RequestMapping("/backstageComment")
        public String backstage_comment(){ return "backstageManagementSystem/backstage_comment";
    }
    @RequestMapping("/businessBackgronud")
    public String businessBackgronud(){
        return "merchant/businessBackgronud";
    }

//    关注的商品和店铺
    @RequestMapping("/concernShop")
    public String concernShop(HttpSession session,Model model){
//        UserDate userDate=(UserDate) session.getAttribute("user");
//        iCarDataService.selectCar(userDate.getUserId());
//        List<GoodsData> list=null;
//        for (CarData carData:iCarDataService.selectCar(userDate.getUserId())){
//            list.add(goodsDateService.selectGoods(Integer.parseInt(carData.getPayment())));
//        }
//        model.addAttribute("date",list);
        return "concern/concernShop";
    }
}
